package com.supermap.gwfs.message.entity;

import java.text.DecimalFormat;

public class ElementValue implements Comparable {
	private int valid;
	private double tMAX;
	private double tMin;
	private double weather;
	private double windR;
	private double windZ;
	private double rain;

	public ElementValue(int valid) {
		this.valid = valid;
		this.tMAX = 999.9d;
		this.tMin = 999.9d;
		this.weather = 999.9d;
		this.windR = 999.9d;
		this.windZ = 999.9d;
		this.rain = 999.9d;
	}
	public ElementValue() {
		this.tMAX = 999.9d;
		this.tMAX = 999.9d;
		this.tMin = 999.9d;
		this.weather = 999.9d;
		this.windR = 999.9d;
		this.windZ = 999.9d;
		this.rain = 999.9d;
	}

	public int getValid() {
		return valid;
	}

	public void setValid(int valid) {
		this.valid = valid;
	}

	public double gettMAX() {
		return tMAX;
	}

	public void settMAX(double tMAX) {
		this.tMAX = tMAX;
	}

	public double gettMin() {
		return tMin;
	}

	public void settMin(double tMin) {
		this.tMin = tMin;
	}

	public double getWeather() {
		return weather;
	}

	public void setWeather(double weather) {
		this.weather = weather;
	}

	public double getWindR() {
		return windR;
	}

	public void setWindR(double windR) {
		this.windR = windR;
	}

	public double getWindZ() {
		return windZ;
	}

	public void setWindZ(double windZ) {
		this.windZ = windZ;
	}

	public double getRain() {
		return rain;
	}

	public void setRain(double rain) {
		this.rain = rain;
	}

	@Override
	public String toString() {
		DecimalFormat df = new DecimalFormat("###0.0");   
		StringBuilder sb = new StringBuilder();
		sb.append(String.format("% 3d", this.valid)).append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		
		sb.append(getFormatVallue(df.format(this.tMAX))).append(" ");
		sb.append(getFormatVallue(df.format(this.tMin))).append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append("999.9").append(" ");
		sb.append(getFormatVallue(df.format(this.weather))).append(" ");
		sb.append(getFormatVallue("0.0")).append(" ");//df.format(this.value20)
		sb.append(getFormatVallue("0.0")).append("\r\n");//df.format(this.value21)
		return sb.toString();
	}

	public String toCityString() {
		DecimalFormat df = new DecimalFormat("###0.0");
		DecimalFormat intDf = new DecimalFormat("###0");
		StringBuilder sb = new StringBuilder();
		sb.append(String.format("%03d", this.valid)).append(" ");

		sb.append(getFormatVallue(intDf.format(this.weather))).append(" ");
		sb.append(getFormatVallue(df.format(this.tMAX))).append(" ");
		sb.append(getFormatVallue(df.format(this.tMin))).append(" ");
		sb.append(getFormatVallue(intDf.format(this.windR))).append(" ");//df.format(this.value20)
		sb.append(getFormatVallue(intDf.format(this.windZ))).append(" ");//df.format(this.value21)
		sb.append(getFormatVallue(df.format(this.rain == 0.0 ? 999.9 : this.rain))).append("\r\n");//df.format(this.value21)
		return sb.toString();
	}

	private String getFormatVallue(String format) {
		String value = format;
		for(int i = 0; i < (5 - format.length()); i++){
			value = " " + value;
		}
		return value;
	}
	@Override
	public int compareTo(Object o) {
		ElementValue sdto = (ElementValue)o;
		int otherValid = sdto.getValid();
		if(this.valid>otherValid){
			return 1;
		}
		return 0;
	}
}
